#!/usr/bin/env bash
cmd=$( basename "$0" )
img="pulsar2:3.3"
dockerName="ljs-pulsar-docker"

function usage() {
    echo "Usage: ${cmd} [-i | -n | -h]" 
    echo "      启动docker"
    echo "      -i: <docker_img>:<docker_tag>, 缺省: ${img}"
    echo "      -n: docker容器名称，缺省: ${dockerName}"
    echo "      -h: 输出此信息"
    exit 1
}

while getopts "i:n:h" arg
do
    case "${arg}" in 
        i)
            img="${OPTARG}"
            shift 2
            ;;
        n)
            dockerName="${OPTARG}"
            shift 2
            ;;
        *)
            usage
            ;;
    esac
done

if [ $# -gt 0 ]
then
    usage
fi

echo "Run image ${img}..."

hostDir="${HOME}/docker_homes/pulsar_home"
etcDir="${HOME}/sys/etc_pulsar"
# liujinsong on 161
user="1172"
group="502"
clientHome="/home/pulsar"

echo run docker image ${img}

# 先删除就得container
docker container rm -f ${dockerName} 2> /dev/null

docker run \
    -u ${user}:${group}\
    --net host \
    --rm \
    -v ${etcDir}/group:/etc/group:ro \
    -v ${etcDir}/sudoers:/etc/sudoers:ro \
    -v ${etcDir}/passwd:/etc/passwd:ro \
    -v ${etcDir}/shadow:/etc/shadow:ro \
    -v ${hostDir}:${clientHome} \
    -v ${HOME}/bin:${clientHome}/bin \
    -v ${HOME}/work/ax650N/pulsar_quick_start_example:/data \
    -v ${HOME}/nfs:${clientHome}/nfs \
    -v ${HOME}/tmp:${clientHome}/tmp \
    -w ${clientHome} \
    --name "${dockerName}" \
    -it \
    ${img}
